<template>
	<a-card :bordered="false">
		<div class="table-page-search-wrapper">
			<a-form layout="inline">
				<a-row :gutter="48">

					<a-col :md="24" :sm="24">
						<a-form-item label="供应商：">
							<a-radio-group default-value="" button-style="solid" v-model="queryParam.orgIdSupplier">
								<a-radio-button value="">
									全部
								</a-radio-button>
								<a-radio-button :value="id"
									v-for="{ id, name } in $util.getOrgList([$businessEnum.ORG_TYPE_ENUM.PRIMARY_SUPPLIER.id, $businessEnum.ORG_TYPE_ENUM.NORMAL_SUPPLIER.id])">
									{{ name }}
								</a-radio-button>
							</a-radio-group>
						</a-form-item>
					</a-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="采购单号">
							<a-input v-model="queryParam.orderNumber" placeholder="请输入采购单号" />
						</a-form-item>
					</a-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="采购时间">
							<a-range-picker :show-time="{ format: 'HH:mm:ss' }" format="YYYY-MM-DD HH:mm:ss"
								:placeholder="['Start Time', 'End Time']" @change="onChange" @ok="onOk" />
						</a-form-item>
					</a-col>

					<a-col :md="!advanced && 8 || 24" :sm="24">
						<span class="table-page-search-submitButtons"
							:style="advanced && { float: 'right', overflow: 'hidden' } || {}">
							<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
							<br>
							<!-- {{queryParam}} -->
							<!--<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>-->
						</span>
					</a-col>

				</a-row>
			</a-form>
		</div>

		<s-table ref="table" size="default" :columns="columns" :data="loadData" :alert="true"
			:rowKey="(record) => record.code">

			<span slot="action" slot-scope="text, record">
				<!-- <a @click="$refs.purchaseDetail.show(record)">发货明细</a> -->
				<a @click="$refs.detailForm1.rukuDetails(record,
					{ materialType })">入库明细</a>
				<a-divider type="vertical" />
				<a @click="$refs.rukuList.show(record,
					{ materialType, orderType })">入库记录</a>
			</span>

		</s-table>

		<!--  订单明细  -->
		<purchase-detail ref="purchaseDetail" />

		<detail-form1 ref="detailForm1" />
		<ruku-list ref="rukuList" />
	</a-card>
</template>

<script>
import { STable } from '@/components'
import { page } from '@/api/modular/main/emsorder/emsOrderManage'

import PurchaseDetail from './purchaseDetail'

import detailForm1 from '../../../materialManagement/purchaseOrderByWaitInStore/detailForm1'
import rukuList from '../../../materialManagement/purchaseOrderByWaitInStore/rukuList'

import moment from 'moment'

export default {
	components: {
		STable,
		PurchaseDetail,

		detailForm1,
		rukuList
	},
	mounted() {
		console.log('路由信息1', this.$route.params)
	},
	data() {
		return {
			advanced: false, // 高级搜索 展开/关闭
			queryParam: { time: '' },  // 查询参数
			columns: [
				{
					title: '序号', width: '80px',
					customRender: (text, record, index) => `${index + 1}`
				},
				{
					title: '采购单号',
					dataIndex: 'orderNumber'
				},
				{
					title: '供应商',
					dataIndex: 'targetOrgName'
				},
				// {
				//   title: '采购数量',
				//   dataIndex: '',
				//   customRender: (text, record, index) => `【没算】`
				// },
				// {
				//   title: '已发数量',
				//   dataIndex: '',
				//   customRender: (text, record, index) => `【没算】`
				// },
				{
					title: '采购时间',
					dataIndex: 'createTime'
				},
				{
					title: '入库完成时间',
					dataIndex: 'completedTime'
				},
				{
					title: '操作',
					dataIndex: 'action',
					width: '250px',
					scopedSlots: { customRender: 'action' }
				}
			],
			// 加载数据方法 必须为 Promise 对象
			loadData: parameter => {
				this.queryParam.materialType = this.materialType
				this.queryParam.orderType = this.orderType
				this.queryParam.cgApplyType = 3
				// if (this.$route.params.year && this.$route.params.mounth) {
				// 	this.queryParam.time = this.$route.params.year + '-' + this.$route.params.mounth
				// } else {
				// 	this.queryParam.time = ''
				// }

				// 该页面需要查询两个状态的订单
				// this.queryParam.executeStatuses = this.executeStatus.join(',')
				return page(Object.assign(parameter, this.queryParam)).then((res) => {
					return res.data
				})
			},
			scheduleProductionVisible: false,
			selectedRowKeys: [],
			selectedRows: [],
			defaultExpandedKeys: [],
			replaceFields: {
				key: 'id',
			},
		}
	},
	computed: {
		moment,
		materialType() {
			return this.$businessEnum.MATERIAL_TYPE_ENUM.material.id
		},
		orderType() {
			return this.$businessEnum.ORDER_TYPE_ENUM.purchaseOrder.id
		},
		executeStatus() {
			return [this.$businessEnum.EXECUTE_STATUS_ENUM.IN_STORE_COMPLETED.id, this.$businessEnum.EXECUTE_STATUS_ENUM.COMPLETED.id]
		},
	},
	created() {
	},
	methods: {
		handleOk() {
			this.$refs.table.refresh()
		},
		onSelectChange(selectedRowKeys, selectedRows) {
			this.selectedRowKeys = selectedRowKeys
			this.selectedRows = selectedRows
		},
		onChange(value, dateString) {
			console.log('Selected Time: ', value);
			console.log('Formatted Selected Time: ', dateString);
			this.queryParam.createTimeStart = dateString[0]
			this.queryParam.createTimeEnd = dateString[1]
		},
		onOk(value) {
			// console.log('onOk: ', this.moment(value[0],'YYYY-MM-DD HH:mm:ss'),this.moment(value[2],'YYYY-MM-DD HH:mm:ss'));
		},
	}
}
</script>